<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
  <style>
    .red {
      background-color: red;
    }
  </style>
</head>

<body>
  <!-- 需求, 在每次点击li的时候, 当前的li添加class, 其余的li删除class -->
  <div id="app">
    <ul>
      <li @click="getClass(index)" :class="{'red':index==current}" v-for="(item, index) in movies">{{item}}</li>
    </ul>
  </div>

  <script>
    const app = new Vue({
      el: "#app",
      data: {
        current: 0,
        movies: ["海王", "海绵宝宝", "running man"]
      },
      methods: {
        getClass: function (index) {
          console.log(index);

          this.current = index
          console.log(this.current);
        }
      }
    })
  </script>
</body>

</html>